<template>
  <!--基本信息  -->
  <!-- <div style="height:590px"> -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="value.type"
      :labelWidth="110"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';

import { getInfoBase } from '@/api/cms-api/projectOperating/program/push';

export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    // console.log("value的值1:",this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
    //如果传入参数不为空，则说明是修改进入，初始化对应数据
    // debugger
    if (this.value != null && (this.value.type == 'edit' || this.value.type == 'show')) {
      //  console.log("value的值2:",this.value);
      this.init();
    }
  },
  methods: {
    selectChange(val) {
      //10041001;
      this.$emit('selectNetworkIssued', val);
    }, //修改时，初始化页面数据
    async init() {
      var twoDate = [];

      // console.log("reFileUrl",this.value.rowData['projectProgramId']);
      // debugger
      var id = this.value.rowData['projectProgramId'];
      const re = await getInfoBase(id);

      if (re.data.projectStartDate != null && re.data.projectEndDate != null) {
        twoDate.push(re.data.projectStartDate); //活动周期-开始
        twoDate.push(re.data.projectEndDate); //活动周期-结束
      }
      // debugger
      this.initForm.forEach(x => {
        if (x.fieldName == 'hdzq') {
          x.initialValue = twoDate;
        } else {
          x.initialValue = re.data[x.fieldName];
        }
      });

      // console.log("reFileUrl",re);
      // console.log("infoBase2:",this.initForm)
    },
    formatDates: function(value) {
      //时间处理函数
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      if (month < 10) {
        month = '0' + month;
      }
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '方案编号',
          fieldName: 'programCode',
          disabled: true,
          initialValue: '系统自动生成'
        },
        {
          type: 'SELECT',
          label: '方案状态',
          fieldName: 'programStatus',
          placeholder: '请选择',
          initialValue: 25281001,
          itemList: this.createDictList('2528'),
          disabled: true
        },
        {
          type: 'SELECT',
          label: '方案下发渠道',
          fieldName: 'programIssuedChannel',
          placeholder: '请选择',
          initialValue: 25301001,
          itemList: this.createDictList('2530'),
          disabled: true
        },
        {
          type: 'RANGE_DATE',
          label: '项目周期',
          fieldName: 'hdzq',
          initialValue: [],
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },

        {
          type: 'SELECT',
          label: '是否全网下发',
          fieldName: 'isNetworkIssued',
          change: this.selectChange,
          placeholder: '请选择',
          initialValue: 10041002,
          itemList: this.createDictList('1004'),
          rules: [{ required: true, message: '必填', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '是否二级审核',
          fieldName: 'isSecondaryAudit',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: true, message: '请选择是否需要二级审核', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '方案名称',
          fieldName: 'programName',
          rows: 2,
          initialValue: '',
          placeholder: '请输入',
          rules: [{ required: true, message: '必填', trigger: 'blur' }, { min: 1, max: 90, message: '长度在 1 到 90 个字符', trigger: 'blur' }] //验证
        },
        {
          type: 'TEXT_AREA',
          label: '方案描述',
          fieldName: 'programDesc',
          rows: 3,
          initialValue: '',
          placeholder: '请输入',
          rules: [{ required: true, message: '必填', trigger: 'blur' }, { min: 1, max: 300, message: '长度在 1 到 300 个字符', trigger: 'blur' }] //验证
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件',
          fieldName: 'fileUrl',
          upload: {
            actionUrl: '/api/file/oss/upload', //上传的地址
            fileTypes: ['pdf', 'jpg', 'png', 'rar', 'ppt','pptx'],
            max: 1024 * 100,
            limit: 5
          },
          initialValue: '',
          disabled: false,
          selfCols: 2
        }
      ];
    },
    formChangeHandle(val) {
      val.programIssuedChannel = '25301001'; //主机厂下发
      this.formValue = val;
      this.$emit('formSave', val);
    }
  }
};
</script>
